<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use DB;
use Cookie;
use Hash;
use App\Http\Controllers\Controller;
//模型
use App\Models\Role;

class PaijingController extends Controller
{
    public function getIndex(){
        //查询派警日志
        $data = DB::table('paijing as p')
            -> leftJoin('room as r','r.id','=','p.room_id')
            -> leftJoin('staff as s','s.id','=','p.staff_id')
            -> select('p.*','r.name as rname','s.name as sname')
            ->orderBy("add_time", "desc")
            -> paginate(3);
        return view('admin.paijing.index',['data'=>$data]);
    }
    //信息更新
    public function postFresh(Request $request){
        $paijing_id = $request -> input('id');
        $info = DB::table("nb_report")
            -> select("num",'type_name','genre','addTime')
            -> where('paijing_id',$paijing_id)
            -> orderBy("addTime", "desc")
            -> paginate(10);
        $data = $info -> all();
        return $data;
    }
    //时间线
    public function postLine(Request $request){
        $line = [];
        $paijing_id = $request -> input('id');
        $info = DB::table('event_record as er')
            -> leftJoin('event as e','e.id','=','er.event_id')
            -> where('er.paijing_id',$paijing_id)
            -> select('er.*','e.name as ename')
            -> orderBy('er.add_time','desc')
            -> get();
        foreach ($info as $v){
            $temp = date('Y-m-d',$v['add_time']);
            if(array_key_exists($temp,$line)){
                $line[$temp][] = date('H:i:s',$v['add_time']).'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['ename'];
            }else{
                $line[$temp] = [];
                $line[$temp][] = date('H:i:s',$v['add_time']).'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['ename'];
            }
        }
        return $line;
    }
}